<?php

//bazine isvedimas ir add
echo "Pasirinktas naujienų modulis:"."";
if($_GET['detail']==null){ //naujienos vivod
echo "naujienos<br>";  
echo "<a href='index.php?module=naujienos&detail=1'>Sukurti naujieną</a><br><br>";
echo "
<table width='400' border='1' cellspacing='0' cellpadding='0' style='border-collapse:collapse;'>
  <tr>
    <td width='26'>Nr.</td>
    <td width='168'>Naujienos pavadinimas</td>
    <td width='97'>Data</td>
    <td width='99'>Veiksmai</td>
  </tr>";
$result=mysql_query("select * from news ORDER BY id DESC"); //meniu isvedimas
$i=0;
while ($row = mysql_fetch_assoc($result)) {
$i++;
echo "<tr>
    <td>$i</td>
    <td>$row[titlas]</td>
    <td>$row[data]</td>
    <td><a href='index.php?module=naujienos&edit=$row[id]&detail=2'>redaguoti</a> &nbsp;&nbsp;&nbsp;<a href='index.php?module=naujienos&delete=$row[id]'>trinti</a></td>
  </tr>";
}
echo "</table>";
}

//delete news
if(is_numeric($_GET['delete'])){
$q1=new queris();
$q1->deletenews($_GET['delete']);
echo "<script>window.location='index.php?module=naujienos';</script>";
}

//naujienos redagavimas
if(is_numeric($_GET['edit'])){
$result=mysql_query("select * from news where id='$_GET[edit]'"); //meniu isvedimas
$row = mysql_fetch_assoc($result);
echo "<br>Naujienos antraštė<br>";  
echo "<form method='post' action='?module=naujienos&detail=2updator=1'>";
echo "<input type=text name='newtitle' style='width:300px' value='$row[titlas]'><br><br>";
echo "<textarea name='newcontent' style='width:100%'>$row[textas]";
echo "</textarea><br>";
echo "<input type='hidden' name='idis' value='$row[id]'>";
echo "<input type=submit style='background-color:red;font-size:10px;color:white;border:0;line-height:normal' name='updator' value='išsaugoti' >&nbsp;&nbsp;&nbsp;&nbsp;";
echo "</form>";
}

//nauja naujiena atvaizdavimas
if($_GET['detail']==1){
echo "<br>Naujienos antraštė<br>";  
echo "<form method='POST' action='?module=naujienos'>";
echo "<input type=text name='newtitle' style='width:300px' value=''><br><br>";
echo "<textarea name='newcontent' style='width:100%'>";
echo "</textarea><br>";
echo "<input type=submit style='background-color:red;font-size:10px;color:white;border:0;line-height:normal' name='nsaver' value='išsaugoti' >&nbsp;&nbsp;&nbsp;&nbsp;</form>";
}

//redaguoto naujienos savingas
if(isset($_POST['updator'])){
$newsupdate=new queris();
$newsupdate->newwsupdate($_POST['newtitle'],$_POST['newcontent'],$_POST['idis']);
echo "<script>window.location='index.php?module=naujienos';</script>";

}

//naujienos irasymas/savinimas
if(isset($_POST['nsaver'])){
$insertnew=new queris();
$insertnew->newsinsert($_POST['newtitle'],$_POST['newcontent']);
$_POST['newtitle']=null;
$_POST['newcontent']=null;
$_POST['nsaver']=null;
echo "<script>window.location='index.php?module=naujienos';</script>";
}

?>